import http from './http';
import constant from './constant';

// 支付订单搜索接口
export const getPayBoardResult = params => http.post(constant.PAYBOARD.GET_SEARCH_RESULT, params);

export const fetchSearchFormOptions = params => http.post(constant.PAYBOARD.PAY_BOARD_SELECT, params);
export const fetchDetail = params => http.post(constant.PAYBOARD.PAY_BOARD_DETAIL, params);
// export const downLoad = params => http.post(constant.REPORTSCHART.TRANSFORM_DOWNLOAD, params);
export const downLoad = ({params, excelName = ''}) => http({
    url: constant.PAYBOARD.PAY_BOARD_DOWNLOAD,
    method: 'post',
    data: {
        ...params
    },
    responseType: 'blob'
}).then(res => {
    const blob = new Blob([res], {
        type: 'application/vnd.ms-excel;'
    });
    const downloadElement = document.createElement('a');
    const href = window.URL.createObjectURL(blob);
    downloadElement.href = href;
    const time = (new Date()).getTime();
    downloadElement.download = `${excelName}${time}.xlsx`;
    // document.body.appendChild(downloadElement);
    downloadElement.click();
    // document.body.removeChild(downloadElement);
    // window.URL.revokeObjectURL(href);
});

